import axios from 'axios';
import { UserPageQueryVO } from './user';

export interface ResourcesVo {
  description: string;
  enableFlag: string;
  name: string;
  parentId: string;
  id: string;
  code: string;
  url: string;
  sysInnerFlag: string;
  type: string;
  menuId: string;
  portalId: string;
}

export interface ResourcesListParams {
  code: string;
  description: string;
  enableFlag: string;
  name: string;
  page: number;
  parentId: string;
  rows: number;
  sysInnerFlag: string;
  type: string;
  url: string;
}

export interface ResourcesAuth {
  code: string;
  id: string;
  icon: string;
  menuId: string;
  name: number;
  type: string;
  url: string;
}
export interface resources {
  id: string;
  name: string;
}
export interface Menu {
  id: string;
  name: string;
  resources: resources[];
}
export interface portal {
  id: string;
  name: string;
  menus: Menu[];
  children: Menu[];
  type?: string;
}

export interface ResourcesListRes {
  rows: ResourcesVo[];
  total: number;
}

export function selectPageResources(params: ResourcesListParams) {
  return axios.post<ResourcesListRes>(
    'tenant/resources/selectPageResources',
    params
  );
}

export function selectResources() {
  return axios.post<ResourcesListRes>('tenant/resources/selectResources', {});
}

export function createResources(params: ResourcesVo) {
  return axios.post<string>('tenant/resources/createResources', params);
}

export function updateResources(params: ResourcesVo) {
  return axios.post<string>('tenant/resources/editResources', params);
}

export function delResources(id: string) {
  return axios.get<string>(`tenant/resources/deleteResources?id=${id}`);
}
export function getResources() {
  return axios.post<portal[]>(`tenant/resources/getAuthorityResource`);
}

// 授权管理下 资源数据查询方法
export function getNoAuthorityResource() {
  return axios.post<any>(`tenant/resources/getNoAuthorityResource`);
}

// 绑定用户资源
export function bindUserAndResource(param: {
  businessId: string;
  userIds: Array<string>;
}) {
  return axios.post('tenant/user/bindUserAndResource', param);
}
// 根据资源id查询绑定的用户
export function selectUserByBindResource(resourceId: string) {
  return axios.post<UserPageQueryVO>(
    `tenant/user/selectUserByBindResource?resourceId=${resourceId}`
  );
}
// 根据资源id查询绑定的用户组
export function selectUserGroupByBindResource(resourceId: string) {
  return axios.post<UserPageQueryVO>(
    `tenant/userGroup/selectUserGroupByBindResource?resourceId=${resourceId}`
  );
}
